package com.pwt.repository;

import com.pwt.common.ResultPage;
import com.pwt.entity.JobNo;
import com.pwt.model.ComboBoxModel;
import com.pwt.model.DataModel;
import com.pwt.repository.base.DataRepositoryExtension;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dw
 * @date 2022/1/20 10:24
 * @Description
 */
public class JobNoRepositoryExtensionImpl extends DataRepositoryExtension<JobNo,String> implements JobNoRepositoryExtension {


    @Override
    public ResultPage queryJobNoPage(Integer page, Integer limit, Integer type, String jobNo) {
        Map<String,Object> map = new HashMap<>();
        String sql = "select * from job_no where 1=1 ";
        String csql = "select count(1) from job_no where 1=1 ";

        if(type != null){
            sql+=" and type=?0";
            csql+="and type=?0";
            map.put("type",type);
        }
        if(StringUtils.isNotBlank(jobNo)){
            sql+=" and job_nos like '%?1%'";
            csql+=" and job_nos like '%?1%'";
            map.put("jobNo",jobNo);
        }
        return super.queryEntityPageBySql(csql,sql,page-1,limit);
    }

    @Override
    public List<ComboBoxModel> queryUserJobNo() {
        String sql = "SELECT distinct username name,job_no id from [user] where job_no is not null ";
        return super.queryCustomBeanListBySql(ComboBoxModel.class,sql);
    }
}
